<?php
	require_once("../conexion/conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="../Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />
<script src="../include_js/jquery.js" type="text/javascript"></script>
<style>
.filaPar
{
	background:#81D371; 
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
.filaImpar
{
	background:#AEF1A1;
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
a:link {text-decoration:line-through; color:#0033FF;} /* Link no visitado*/
a:visited {text-decoration:none; color:#999900} /*Link visitado*/
a:hover {text-decoration:underline; color:#990000;} /*Mouse sobre el link*/
</style>
<script>
function Formulario(valor)
{
	
	id = document.getElementById("tbOtros").rows[valor].cells[0].innerText;
	numero = document.getElementById("tbOtros").rows[valor].cells[1].innerText;
	//alert(id+" "+numero);
	window.open("Produccion/Ventana_Otros.php?id="+id+"&num="+numero,"VentanaResumenOtros","width=550,height=480,scrollbars=yes");
}

function Eliminar(valor)
{
	id = document.getElementById("tbOtros").rows[valor].cells[0].innerText;
	numero = document.getElementById("tbOtros").rows[valor].cells[1].innerText;
	//alert(id+" "+numero);
	$.ajax({
					type: 'POST',
					url: 'Produccion/Eliminar_Otros.php',
					data: {id:id,numero:numero},
					success: function(data) {
						$('#eliminar').html(data);
						Direccionar();
					}
				})
}

function Direccionar()
{
	//alert('dir');
		$.ajax({
				type: 'POST',
				url: 'Produccion/carga_busqueda_decl_3.php',
				data: $('#form_Busqueda_Decl').serialize(),
				success: function(data) {
					$('#capa').html(data);
				}
			})
}
</script>
</head>

<body>
<form name="busqueda_otros" id="busqueda_otros" method="post">
<?php
	extract($_POST);
 
	$cont = 0;
	
 	if ($txtTitulo=="")
	{
		$txtTitulo="null";
		$cont++;
	}
	else
	{$txtTitulo="'".$txtTitulo."'";}
	
	if ($txtOrden=="") {
		$txtOrden="null";
		$cont++;
	}
	else
	{$txtOrden="'".$txtOrden."'";}
	
	if ($txtTitular=="") {
		$txtTitular="null";
		$cont++;
	}
	else
	{$txtTitular="'".$txtTitular."'";}
	
	//fecha inicio
	if ($txtFIni==""){
		$txtFIni="null";
		$cont++;
	}
	else
	{
		$FechaIni = explode("-", $txtFIni);
		$txtFIni = "$FechaIni[2]-$FechaIni[1]-$FechaIni[0]";
	}
	//fecha fin
	if ($txtFFin==""){
		$txtFFin="null";
		$cont++;
	}
	else
	{
		$FechaFin = explode("-", $txtFFin);
		$txtFFin = "$FechaFin[2]-$FechaFin[1]-$FechaFin[0]";
	}
	
	
	if($cont != 5)
	{
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
		$sql = "select
				OtrosCod,
				OtrosNumOrden,
				OCliRSocial,
				TOtrosNombre,
				date_format(OtrosFecha,'%d/%m/%Y') as fecha,
				OtrosValor
				
				from otros
				inner join otrosclientes on
				otrosclientes.OCliRut=otros.OCliRut
				inner join tipootros on
				tipootros.TOtrosCod=otros.TOtrosCod
				
				where
				(($txtTitulo is NULL) or (OtrosTitulo = $txtTitulo)) and
				(($txtOrden is NULL) or (OtrosNumOrden = $txtOrden)) and
				(($txtTitular is NULL) or (OCliRSocial = $txtTitular)) and
				((($txtFIni is NULL) and ($txtFFin is NULL)) or DATE(OtrosFecha) BETWEEN '".$txtFIni."' and '".$txtFFin."')";
				//echo $sql;
			$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
			$fila = mysql_num_rows($res);
			if($fila >0)
			{?>
			<table width="100%" border="0" class="uno" cellpadding="0" cellspacing="0" id="tbOtros">
			<thead>
			  <tr>
			  	<th width="3%">id</th>
				<th width="10%">N&deg; Orden</th>
			    <th width="35%">cliente</th>
				<th width="24%">tipo</th>
			    <th width="11%">Fecha</th>
				<th width="11%">valor ($)</th>
				<th width="6%" colspan="2">accion</th>
			  </tr>
			 </thead>
			 <?php
			 	$aux =1;
				$cont=1;
				while($reg = mysql_fetch_array($res))
				{
					if(($cont % 2)==0)
					{
						echo "<tr class='FilaPar' id='".$aux."'>";
						echo "<td width=\"3%\" style='text-align:center'>".$reg['OtrosCod']."</td>";
						echo "<td width=\"10%\" style='text-align:center'>".$reg['OtrosNumOrden']."</td>";
						echo "<td width=\"35%\">".$reg['OCliRSocial']."</td>";
						echo "<td width=\"24%\" style='text-align:center'>".$reg['TOtrosNombre']."</td>";
						echo "<td width=\"11%\" style='text-align:center'>".$reg['fecha']."</td>";
						echo "<td width=\"11%\" style='text-align:center'>".number_format($reg['OtrosValor'],0,',','.')."</td>";
						echo "<td style='text-align:center'><img src='imagen/edit_icon.gif' width='16' height='16' alt='Editar' style='cursor: pointer;' onclick='Formulario($aux);'/></td>";
			echo "<td style='text-align:center'><img src='imagen/delete_icon.gif' width='16' height='16' alt='Eliminar' style='cursor: pointer;' onclick='Eliminar($aux);'/></td>";
						echo "</tr>";
					}
					else
					{
						echo "<tr class='FilaImpar' id='".$aux."'>";
						echo "<td width=\"3%\" style='text-align:center'>".$reg['OtrosCod']."</td>";
						echo "<td width=\"10%\" style='text-align:center'>".$reg['OtrosNumOrden']."</td>";
						echo "<td width=\"35%\">".$reg['OCliRSocial']."</td>";
						echo "<td width=\"24%\" style='text-align:center'>".$reg['TOtrosNombre']."</td>";
						echo "<td width=\"11%\" style='text-align:center'>".$reg['fecha']."</td>";
						echo "<td width=\"11%\" style='text-align:center'>".number_format($reg['OtrosValor'],0,',','.')."</td>";
						echo "<td style='text-align:center'><img src='imagen/edit_icon.gif' width='16' height='16' alt='Editar' style='cursor: pointer;' onclick='Formulario($aux);'/></td>";
			echo "<td style='text-align:center'><img src='imagen/delete_icon.gif' width='16' height='16' alt='Eliminar' style='cursor: pointer;' onclick='Eliminar($aux);'/></td>";
						echo "</tr>";
					}
					$cont++;
					$aux++;
				}
				$con->cerrarBD();
				?></table><?php
			}
			else
				{echo "<label style=\"font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;\">La b&uacute;squeda no gener&oacute; resultados.</label>";}
	}
 ?>
</table>
<div id="eliminar"></div>
</form>
</body>
</html>
